/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * wageTableDialog.java
 *
 * Created on 2011-6-1, 10:56:06
 */
package junchangmis.teacher;

import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import junchangmis.*;
import jxl.write.WriteException;
import publicmethod.*;
import java.util.Vector;
import java.sql.ResultSet;
import javax.swing.JOptionPane;

/**
 *
 * @author developers
 */
public class wageTableDialog extends javax.swing.JDialog {

    MainFrame parent;
    Vector<teacher> tea = new Vector();

    /** Creates new form wageTableDialog */
    public wageTableDialog(java.awt.Frame parent, boolean modal, MainFrame pparent) {
        super(parent, modal);
        this.parent = pparent;
        initComponents();
        this.setTitle("年月选择");
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jComboBoxYear = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxMonth = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jCheckBoxPrint = new javax.swing.JCheckBox();
        jButtonConfirm = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("华文细黑", 0, 24));
        jLabel1.setText("选择年月");

        jComboBoxYear.setFont(new java.awt.Font("华文细黑", 0, 24));
        jComboBoxYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        jLabel2.setFont(new java.awt.Font("华文细黑", 0, 24));
        jLabel2.setText("年");

        jComboBoxMonth.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jComboBoxMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));

        jLabel3.setFont(new java.awt.Font("华文细黑", 0, 24));
        jLabel3.setText("月");

        jCheckBoxPrint.setFont(new java.awt.Font("华文细黑", 0, 24));
        jCheckBoxPrint.setText("是否打印");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(67, 67, 67)
                        .addComponent(jComboBoxYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(125, 125, 125)
                        .addComponent(jCheckBoxPrint)))
                .addContainerGap(88, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBoxYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addComponent(jCheckBoxPrint)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jComboBoxMonth, jComboBoxYear});

        jButtonConfirm.setFont(new java.awt.Font("华文细黑", 0, 24)); // NOI18N
        jButtonConfirm.setText("确定");
        jButtonConfirm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfirmActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel1)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonConfirm))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonConfirm, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmActionPerformed
        try {
            // TODO add your handling code here:
            DbOperation db = new DbOperation();
            db.DbConnect();
            String sql = "select * from teacher where yearStart='" + this.jComboBoxYear.getSelectedItem().toString() + "' and monthStart='" + this.jComboBoxMonth.getSelectedItem().toString() + "' order by name";
            ResultSet rs = db.DBSqlQuery(sql);
            while (rs.next()) {
                teacher temp = new teacher();
                temp.yearStart = rs.getString("yearStart");
                temp.monthStart = rs.getString("monthStart");
                temp.dayStart = rs.getString("dayStart");
                temp.yearEnd = rs.getString("yearEnd");
                temp.monthEnd = rs.getString("monthEnd");
                temp.dayEnd = rs.getString("dayEnd");
                temp.week = rs.getString("week");
                temp.name = rs.getString("name");
                temp.classCode = rs.getString("classCode");
                temp.classCount = rs.getString("classCount");
                temp.listenCount = rs.getString("listenCount");                

                tea.add(temp);
            }
            db.DbClose();
        } catch (SQLException ex) {
            Logger.getLogger(dutyYMTableDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (tea.size() > 0) {
            try {
                String ym = this.jComboBoxYear.getSelectedItem().toString() + "年" + this.jComboBoxMonth.getSelectedItem().toString() + "月";
                wageTableExcel work = new wageTableExcel(tea, ym);
                String filename = "教师考勤考及工资一览表\\";
                filename = filename + this.jComboBoxYear.getSelectedItem().toString() + "年" + this.jComboBoxMonth.getSelectedItem().toString() + "月考勤考核表.xls";
                work.setOutputFile(filename);
                work.write();
                System.out.println("Please check the result file " + filename);
                JOptionPane.showConfirmDialog(null, "生成成功！", "提示", JOptionPane.CLOSED_OPTION, JOptionPane.INFORMATION_MESSAGE);
                if (this.jCheckBoxPrint.isSelected() == true) {
                    PrintTest.print(PrintTest.getPath() + "\\" + filename);
                } else {
                    PrintTest.showTable(PrintTest.getPath() + "\\" + filename);
                }
                dispose();
            } catch (WriteException ex) {
                Logger.getLogger(dutyYMTableDialog.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(dutyYMTableDialog.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            JOptionPane.showConfirmDialog(null, "没有记录！", "提示", JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE);
        }
}//GEN-LAST:event_jButtonConfirmActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*        java.awt.EventQueue.invokeLater(new Runnable() {
        
        public void run() {
        wageTableDialog dialog = new wageTableDialog(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
        
        public void windowClosing(java.awt.event.WindowEvent e) {
        System.exit(0);
        }
        });
        dialog.setVisible(true);
        }
        });*/
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonConfirm;
    private javax.swing.JCheckBox jCheckBoxPrint;
    private javax.swing.JComboBox jComboBoxMonth;
    private javax.swing.JComboBox jComboBoxYear;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
